package com.lorenzogao.pley.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.lorenzogao.pley.R
import com.lorenzogao.pley.bean.AppInfo
import com.squareup.picasso.Picasso

/**
 * Created by GanLanPing
 * data:2017/12/23
 * time:1:16
 * 邮箱:2508719070@qq.com
 * Description:
 */
class RecomendAppAdapter (private var context: Context, private var datas: List<AppInfo>) : RecyclerView.Adapter<RecomendAppAdapter.ViewHoulder>() {

    private var mDatas: List<AppInfo> = datas
    private var mContext: Context = context
    private val mLayoutInflater: LayoutInflater = LayoutInflater.from(context)

    override fun getItemCount(): Int {
        return if (mDatas == null) 0 else mDatas.size
    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHoulder {
        return ViewHoulder(mLayoutInflater.inflate(R.layout.template_recomend_app, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHoulder?, position: Int) {
        holder!!.tv_title.text = mDatas[position].displayName

        holder!!.tv_size.text = (mDatas[position].apkSize / 1024 / 1024).toString() + "MB"
        var baseImgUrl = "http://file.market.xiaomi.com/mfc/thumbnail/png/w150q80/"
        Picasso.with(mContext).load(baseImgUrl + mDatas[position].icon).into(holder.iv_icon)
    }


    class ViewHoulder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
         var tv_title: TextView = itemView!!.findViewById(R.id.tv_title)
         var tv_size: TextView = itemView!!.findViewById(R.id.tv_size)
         var iv_icon: ImageView = itemView!!.findViewById(R.id.img_icon)
         var btn_download: Button = itemView!!.findViewById(R.id.btn_download)


    }
}


